<?php
// 节点模型
class NodeModel extends CommonModel {
    protected $_validate	=	array(
        array('name','checkNode','节点已经存在',0,'callback'),
        );

    public function checkNode() {
        $map['name']	 =	 $_POST['name'];
        $map['pid']	=	isset($_POST['pid'])?$_POST['pid']:0;
        $map['status'] = 1;
        if(!empty($_POST['id'])) {
            $map['id']	=	array('neq',$_POST['id']);
        }
        $result	=	$this->where($map)->field('id')->find();
        if($result) {
            return false;
        }else{
            return true;
        }
    }
    /**
     * 读取数据库模块列表生成菜单项
     * @param unknown $level
     * @param unknown $status
     * @param unknown $pid	
     * @return Ambigous <mixed, boolean, multitype:, multitype:multitype: >
     */
    public function getNodeGroupList($level,$status,$pid) {
    	$table = $this->tablePrefix.'node';
    	$rs = $this->db->query('select a.id,a.title as text,a.name,b.name as gname,b.id as gid,b.title as gtitle from '.$table.' as a ,'.$this->tablePrefix.'group as b where a.group_id=b.id and  a.pid='. $pid .' and a.level='.$level.' and a.status='.$status.' order by a.sort asc ');
    	return $rs;
    }
    
    
    
}